var _tools = require("../../../utils/tools.js"), _tools2 = _interopRequireDefault(_tools);

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var that, app = getApp();
let interstitialAd = null;

Page({
    data: {
        motto: "Hello World",
        userInfo: {},
        hasUserInfo: !1,
        canIUse: wx.canIUse("button.open-type.getUserInfo"),
        showBack: 0,
        height: 2 * app.globalData.height + 20,
        loading: !1,
        shareshow: !1,
        nav: {
            title: "公共福利",
            showHome: !1,
            isHomePage: !0
        },
        characters: [ "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" ],
        showcopy: !0,
        share: {
            images: "",
            member_id: "",
            text: ""
        }
    },
    gotoMy: function(t) {
        wx.reLaunch({
            url: "../my/my"
        });
    },
    onReady: function() {
        wx.setNavigationBarColor({
            frontColor: "#000000",
            backgroundColor: "#000000"
        });
    },
    gotoSgin: function() {
        wx.navigateTo({
            url: "/packageA/pages/signin/signin"
        });
    },
    onLoad: function(t) {
        that = this, t.parent_id && wx.setStorageSync("parent_id", t.parent_id), t.scene && wx.setStorageSync("parent_id", decodeURIComponent(t.scene)), 
        !1 === wx.getStorageSync("home_showcopy") && that.setData({
            showcopy: !1
        });
    },
    onPullDownRefresh: function() {
        wx.showNavigationBarLoading(), that.onShow();
    },
    gotoTask: function() {
        wx.navigateTo({
            url: "/packageA/pages/task/task"
        });
    },
    onShow: function() {
        var e = wx.getUpdateManager();
        e && e.onCheckForUpdate && (e.onCheckForUpdate(function(t) {
            console.log(t.hasUpdate);
        }), e.onUpdateReady(function() {
            wx.showModal({
                title: "更新提示",
                content: "新版本已经准备好，是否重启应用？",
                success: function(t) {
                    t.confirm && e.applyUpdate();
                }
            });
        }), e.onUpdateFailed(function() {
            wx.showModal({
                title: "更新提示",
                content: "新版本下载失败",
                showCancel: !1
            });
        }));
        var t = {
            action: "index",
            contr: "luck",
            token: wx.getStorageSync("token")
        };
        _tools2.default.request(t, function(t) {
            that.setData(t.info), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
        });

        // 在页面onShow回调事件中创建插屏广告实例
if (wx.createInterstitialAd) {
    interstitialAd = wx.createInterstitialAd({
      adUnitId: 'adunit-42e141bfcfdcc315'
    })
    interstitialAd.onLoad(() => {})
    interstitialAd.onError((err) => {})
    interstitialAd.onClose(() => {})
  };
  
  // 在适合的场景显示插屏广告
  if (interstitialAd) {
    interstitialAd.show().catch((err) => {
      console.error(err)
    })
  };
  
    },
    share: function() {
        that.setData({
            shareshow: !0
        });
    },
    sharehide: function() {
        that.setData({
            shareshow: !1
        });
    },
    gotodrawLottery: function(t) {
        wx.navigateTo({
            url: "/bh_bargain/pages/entrance/entrance"
        });
    },
    goIndexIntro: function() {
        wx.navigateTo({
            url: "/bh_bargain/pages/goIndexIntro/goIndexIntro"
        });
    },
    goShare: function() {
        wx.navigateTo({
            url: "/bh_bargain/pages/share/share"
        }), this.sharehide();
    },
    gotoInfo: function(t) {
        var e = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/bh_bargain/pages/userGame/userGame?id=" + e
        });
    },
    copyText: function(t) {
        var e = t.currentTarget.dataset.value;
        wx.setClipboardData({
            data: e,
            success: function(t) {
                wx.showToast({
                    title: "复制成功"
                }), that.closecopy();
            }
        });
    },
    closecopy: function() {
        that.setData({
            showcopy: !1
        }), wx.setStorageSync("home_showcopy", !1);
    },
    onShareAppMessage: function() {
        return {
            title: this.data.share.text,
            imageUrl: this.data.share.images,
            path: "bh_bargain/pages/index/index?parent_id=" + this.data.share.member_id
        };
    },
    onShareTimeline: function() {
        return {
            title: this.data.share.text,
            query: {
                parent_id: this.data.share.member_id
            },
            imageUrl: this.data.share.images
        };
    }
});